/*
 * @Author: fjt
 * @Date: 2021-07-07 21:25:33
 * @LastEditors: fjt
 * @LastEditTime: 2021-07-20 23:12:10
 */
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

module.exports = {
  lintOnSave: false,
  pages: {
    index: {
      entry: './src/main.js',
      template: './public/index.html',
      filename: 'index.html',
      title: 'leadshop',
      chunks: ['leadshop', 'commom', 'echarts', 'element-ui', 'index']
    }
  },
  devServer: {
    open: true,
    overlay: {
      warnings: true,
      errors: true
    }
  },
  publicPath: process.env.NODE_ENV === 'production' ? '/assets/admin' : '/',
  filenameHashing: true,
  productionSourceMap: true,
  configureWebpack: config => {
    config.optimization.splitChunks = {
      cacheGroups: {
        common: {
          name: 'commom',
          minChunks: 2,
          priority: -20,
          chunks: 'initial',
          reuseExistingChunk: true
        },
        leadshop: {
          name: 'leadshop',
          test: /[\\/]node_modules[\\/]/,
          chunks: 'initial',
          priority: -10
        },
        echarts: {
          name: 'echarts',
          test: /[\\/]node_modules[\\/]_?echarts(.*)/,
          chunks: 'initial',
          priority: 10
        },
        'element-ui': {
          name: 'element-ui',
          test: /[\\/]node_modules[\\/]_?element-ui(.*)/,
          chunks: 'initial',
          priority: 10
        }
      }
    };

    if (process.env.BUNDLE_ANALYZER === 'YES') {
      return {
        plugins: [new BundleAnalyzerPlugin()]
      };
    }
  },
  chainWebpack: config => {}
};
